﻿using System;
using System.Runtime.Serialization;
using Grundy.Common;

namespace Grundy.Message
{
    
    [DataContract]
    public class FeatureIdentificationKey
    {
        public override string ToString()
        {
            return "{{ Feature Id: {0}, Feature: {1}, License Entitlement Id: {2}, License: {3}, Product Id: {4}, Product: {5}, CustomerId: {6}, Customer: {7} }}"
                                     .FormatWith(FeatureId, FeatureName, LicenseEntitlementId, LicenseName, ProductId, ProductName, CustomerId, CustomerName);
        }

        public bool Equals(FeatureIdentificationKey other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other.CustomerId.Equals(CustomerId) && other.ProductId.Equals(ProductId) && other.LicenseEntitlementId.Equals(LicenseEntitlementId) && other.LicenseId.Equals(LicenseId) && other.FeatureId.Equals(FeatureId) && Equals(other.CustomerName, CustomerName) && Equals(other.ProductName, ProductName) && Equals(other.LicenseName, LicenseName) && Equals(other.FeatureName, FeatureName);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (FeatureIdentificationKey)) return false;
            return Equals((FeatureIdentificationKey) obj);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int result = CustomerId.GetHashCode();
                result = (result*397) ^ ProductId.GetHashCode();
                result = (result*397) ^ LicenseEntitlementId.GetHashCode();
                result = (result*397) ^ LicenseId.GetHashCode();
                result = (result*397) ^ FeatureId.GetHashCode();
                result = (result*397) ^ (CustomerName != null ? CustomerName.GetHashCode() : 0);
                result = (result*397) ^ (ProductName != null ? ProductName.GetHashCode() : 0);
                result = (result*397) ^ (LicenseName != null ? LicenseName.GetHashCode() : 0);
                result = (result*397) ^ (FeatureName != null ? FeatureName.GetHashCode() : 0);
                return result;
            }
        }

        public static bool operator ==(FeatureIdentificationKey left, FeatureIdentificationKey right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(FeatureIdentificationKey left, FeatureIdentificationKey right)
        {
            return !Equals(left, right);
        }

        public FeatureIdentificationKey()
        {
            
        }

        [DataMember]
        public Guid CustomerId { get; set; }

        [DataMember]
        public Guid ProductId { get; set; }

        [DataMember]
        public Guid LicenseEntitlementId { get; set; }

        [DataMember]
        public Guid LicenseId { get; set; }

        [DataMember]
        public Guid FeatureId { get; set; }


        [DataMember]
        public string CustomerName { get; set; }

        [DataMember]
        public string ProductName { get; set; }

        [DataMember]
        public string LicenseName { get; set; }

        [DataMember]
        public string FeatureName { get; set; }

        public static FeatureIdentificationKey Null{get{return new FeatureIdentificationKey();}}

        public bool IsEmpty()
        {
            return this == FeatureIdentificationKey.Null;
        }
    }
}